<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"/>
    <title>23-生命周期</title>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body>
<div id="app" v-cloak></div>
<script src="js/vue.js"></script>
<script>
    let App = {
        template: `
            <div>
                {{name}}
                <button type="button" v-on:click="name='李四'">改名</button>
                <div v-if="isShow">
                    <input type="text" ref="username" placeholder="请输入用户名">
                </div>
                <button type="button" v-on:click="isShow=true">显示Input</button>
            </div>
        `,
        data() {
            return {
                name: "张三"
            }
        },
        //初始化之前
        beforeCreate() {
            console.log("beforeCreate");
        },
        //初始化完成（不能获取dom，一般用于获取ajax数据）
        created() {
            console.log("created");
        },
        //挂载之前
        beforeMount() {
            console.log("beforeMount");
        },
        //挂载完成之后（可以获取dom）
        mounted() {
            console.log("mounted");
        },
        //数据更新之前
        beforeUpdate() {
            console.log("beforeUpdate");
        },
        /*
       * 1、更新数据之后获取焦点
       * 2、动态获取dom的属性
       * 3、更新数据之后对dom进行操作
       * */
        updated() {
            console.log("updated");
            this.$refs["username"].focus();
            console.log(this.$refs["username"].getAttribute("type"));
        }

    };
    new Vue({
        el: "#app",
        template: `
            <App></App>
        `,
        components: {
            App
        }
    })
</script>
</body>
</html>
